package com.health.controller;

import com.health.entity.Order;
import com.health.result.R;
import com.health.result.Result;
import com.health.service.PayService;
import com.health.vo.OrderPaymentVO;
import com.health.vo.OrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/pay")
public class PayController {

    @Autowired
    private PayService payService;

    @GetMapping("/order")
    public R pay(Integer money) throws Exception {
        OrderPaymentVO vo = payService.pay(money);
        return R.success(vo);
    }

    //支付回调
    @GetMapping("/callback")
    public R payCallback(String outTradeNo, Integer amount) {

        if(payService.payCallback(outTradeNo, amount)){
            return R.success();
        }
        return R.error("支付失败");
    }
}
